package com.zfx.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @description:  登录拦截器
 * @author: zfx
 */
public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException {
        Object userId = request.getSession().getAttribute("loginId");
        if (userId == null) {
            response.sendRedirect(request.getContextPath()+"/login.html");
            return false;
        } else {
            return true;
        }
    }
}
